package com.chen.scaffolding.nacosserver.controller;


import com.chen.scaffolding.nacosconfig.entity.Authority;
import com.chen.scaffolding.nacosserver.entity.UserEntity;
import com.chen.scaffolding.nacosserver.service.UserService;
import com.chen.scaffolding.nacosserver.service.impl.OpenFeignAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * nacos 服务注册
 * @author :master
 */

@RestController
@RequestMapping("/server")
@RefreshScope
public class NacosServerController {
    @Autowired
    private UserService userService;
    @Value("${server.port}")
    private String port;

    @Value("${test.nacos}")
    private String values;

    @RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
    public String echo(@PathVariable String string) {
        return "Hello Nacos Discovery " + string;
    }

    @RequestMapping("/get")
    public String get() {
        return values;
    }

    @RequestMapping("/getProt")
    public String getProt() {
        return port;
    }

    @RequestMapping("/addUser")
    public String addUser() {
        UserEntity userEntity = new UserEntity();
        userEntity.setUserId("2");
        userEntity.setUserName("小梦");
        userEntity.setStatus("0");
        try {
            userService.addUser(userEntity);
            return "新增成功";
        }catch (Exception e) {
            return e.getMessage();
        }
    }
}
